<template>
  <div id="app" :class="['app-background', backgroundClass]">
    <router-view v-if="isRouterAlive" />

    <!-- 悬浮球，登录页面不显示 -->
    <div v-if="showFloatingBall" class="floating-ball" @click="toggleMenu">
      <i class="icon-leaf" /> <!-- 悬浮球的图标 -->
    </div>

    <!-- 悬浮球菜单 -->
    <div class="floating-menu" v-if="showFloatingMenu">
      
      <div class="menu-item" @click="refreshPage">
        <i class="icon-top" /> 回顶部
      </div>
     
      <div class="menu-item" @click="toggleBackground">
        <i class="icon-background" /> 切换背景
      </div>
      <div class="menu-item">
        <i class="icon-home" /> 联系我们
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isRouterAlive: true,
      showFloatingMenu: false, // 控制菜单显示
      backgroundClass: 'background-1', // 默认背景图片类
    };
  },
  computed: {
    showFloatingBall() {
      // 在登录页面不显示悬浮球
      return this.$route.path !== '/login';
    },
  },
  methods: {
    toggleMenu() {
      this.showFloatingMenu = !this.showFloatingMenu; // 切换悬浮球菜单显示状态
    },
    refreshPage() {
      // location.reload(); // 刷新页面，模拟回到顶部的功能
      window.scrollTo({
      top: 0,
      left: 0,
      behavior: 'smooth' // 'smooth' 使滚动平滑进行
    });
    },
  
    toggleBackground() {
      // 切换背景图片，通过循环切换 background-1, background-2, background-3
      if (this.backgroundClass === 'background-1') {
        this.backgroundClass = 'background-2';
      } else if (this.backgroundClass === 'background-2') {
        this.backgroundClass = 'background-3';
      } else {
        this.backgroundClass = 'background-1';
      }
    },
  },
};
</script>

<style lang="less">
#app {
  height: 100%;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

/* 默认背景图片 */
.background-1 {
  background-image: url('/back.jpg');
}

/* 切换的第二张背景图片 */
.background-2 {
  background-image: url('/black2.jpg');
}

/* 切换的第三张背景图片 */
.background-3 {
  background-image: url('/black3.jpg');
}

.floating-ball {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  background-color: #4CAF50; /* 绿色背景 */
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 1000;
}

.floating-ball i {
  font-size: 28px;
  color: #fff;
}

.floating-menu {
  position: fixed;
  bottom: 100px;
  right: 30px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  padding: 10px 0;
}

.menu-item {
  padding: 10px;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.menu-item i {
  margin-right: 8px;
  font-size: 20px;
}

.menu-item:hover {
  background-color: #f0f0f0;
}

.icon-leaf::before {
  content: '🍃'; /* 悬浮球图标 */
}
.icon-top::before {
  content: '🔝'; /* 回顶部图标 */
}
.icon-home::before {
  content: '🏡'; /* 回首页图标 */
}
.icon-background::before {
  content: '🖼️'; /* 切换背景图标 */
}
</style>
